home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / misc / emu / ATUtilities.lha / ATUtilities / tr.c < prev    next >
C/C++ Source or Header  |  2000-09-26  |  35KB  |  1,439 lines

  1. /* ******************************************************************* */
  2. /* **                                                               ** */
  3. /* **                     ATUtilities Disk Transfer                 ** */
  4. /* **            Copright (C) 1992-1994 by Thomas Dreibholz         ** */
  5. /* **                      All rights reserved                      ** */
  6. /* **                                                               ** */
  7. /* ******************************************************************* */
  8.  
  9. #include <devices/trackdisk.h>
  10. #include "janus.h"
  11. #include "ATUtilities.h"
  12.  
  13. #define BIT15 (1<<15)
  14. #define AMIGA  0
  15. #define PC720K 1
  16. #define PC144M 2
  17.  
  18. struct UDevice
  19. {
  20.  UBYTE              Name[100];
  21.  UWORD              Unit;
  22.  ULONG              Heads;
  23.  ULONG              SectorsPerTrack;
  24.  ULONG              Tracks;
  25.  UWORD              Motor;
  26.  UWORD              DeviceType;
  27.  BOOL               File;
  28. };
  29.  
  30. struct TDevice
  31. {
  32.  BOOL               Valid;
  33.  ULONG              Changes;
  34.  struct FileHandle *FileHandle;
  35.  struct IOStdReq   *Request;
  36.  struct MsgPort    *Port;
  37.  LONG               Device;
  38. };
  39.  
  40. struct UDevice ud[8]=
  41. {
  42.  "trackdisk.device",0,2,11,80,4,0,FALSE,
  43.  "trackdisk.device",1,2,11,80,4,0,FALSE,
  44.  "trackdisk.device",2,2,22,80,4,0,FALSE,
  45.  "M:File01",0,2,11,80,0,0,TRUE,
  46.  "M:File02",0,3,11,80,0,0,TRUE,
  47.  "mfm.device",0,2,9,80,4,PC720K,FALSE,
  48.  "mfm.device",1,2,9,80,4,PC720K,FALSE,
  49.  "mfm.device",2,2,18,80,4,PC144M,FALSE
  50. };
  51.  
  52. struct TDevice td[8]=
  53. {
  54.  TRUE,10000000L,NULL,NULL,NULL,-1L,
  55.  TRUE,10000000L,NULL,NULL,NULL,-1L,
  56.  TRUE,10000000L,NULL,NULL,NULL,-1L,
  57.  TRUE,10000000L,NULL,NULL,NULL,-1L,
  58.  TRUE,10000000L,NULL,NULL,NULL,-1L,
  59.  TRUE,10000000L,NULL,NULL,NULL,-1L,
  60.  TRUE,10000000L,NULL,NULL,NULL,-1L,
  61.  TRUE,10000000L,NULL,NULL,NULL,-1L
  62. };
  63.  
  64. UWORD Active;
  65. UWORD MotorCNT[8]={0,0,0,0,0,0,0,0};
  66.  
  67. UBYTE *TransferPort="ATUtilities Disk Transfer";
  68. UBYTE *PrefsName="AT:Prefs/DiskTransfer.prefs";
  69. UBYTE *HelpName="AT:Help/DiskTransfer.help";
  70.  
  71. struct JanusBase *JanusBase;
  72. struct Library   *GfxBase;
  73. struct Library   *IntuitionBase;
  74. struct Library   *ATUtilitiesBase;
  75.  
  76. struct Process      *MotorTask;
  77. struct Task         *MainTask;
  78. struct MsgPort      *TaskPort,*ReplyPort;
  79. struct ExtSetupSig  *ExtSetupSig;
  80. struct Window       *WindowPtr;
  81. struct RastPort     *rp;
  82. struct CommMemory   *jhbyte,*jhword;
  83. struct AppManager   *app;
  84. struct Message       Message;
  85. struct Message      *AppMessage;
  86.  
  87. LONG  JanusSignal;
  88. LONG  PortSignal;
  89. LONG  TaskSignal;
  90. ULONG JanusSignalMask;
  91. ULONG PortSignalMask;
  92. ULONG WaitSignalMask;
  93. ULONG TaskSignalMask;
  94. ULONG AppSignalMask;
  95. ULONG Signale;
  96.  
  97. VOID HandleInt();
  98. VOID ShowInfo();
  99. VOID Motor();
  100. VOID EditiereLW();
  101. VOID ZeigeLW();
  102. BOOL EinstellungenAendern();
  103. VOID InstallAll();
  104. VOID UninstallAll();
  105. VOID InstallFile();
  106. VOID UninstallFile();
  107. VOID InstallDevice();
  108. VOID UninstallDevice();
  109. VOID OpenAll();
  110. VOID CloseAll();
  111. VOID Bearbeite();
  112. VOID BearbeiteFile();
  113. WORD ChangeCheck();
  114. VOID CalcFAT();
  115. VOID MotorOnOff();
  116. VOID Format();
  117. VOID Kopiere();
  118.  
  119. UBYTE           *mem;
  120. struct MsgPort  *Port;
  121.  
  122.  
  123. /* Installationsroutine */
  124. VOID main()
  125. {
  126.  REGISTER UWORD i;
  127.  REGISTER BOOL  bool;
  128.  
  129.  OpenAll();
  130.  bool=FALSE;
  131.  while(bool==FALSE)
  132.   {
  133.    Signale=Wait(WaitSignalMask);
  134.    if(Signale & PortSignalMask)
  135.     {
  136.      i=Received(Port);
  137.      switch(i)
  138.       {
  139.        case UTILITY_CALL:
  140.          bool=EinstellungenAendern();
  141.         break;
  142.        case UTILITY_QUIT:
  143.          bool=ExitWarning();
  144.         break;
  145.        case UTILITY_INFO:
  146.          ShowInfo();
  147.         break;
  148.        case UTILITY_HELP:
  149.          Help(HelpName,0);
  150.         break;
  151.       }
  152.     }
  153.    if(Signale & JanusSignalMask)
  154.     {
  155.      HandleInt();
  156.     }
  157.    if(Signale & TaskSignalMask)
  158.     {
  159.      for(i=0;i<8;i++)
  160.       {
  161.        if(MotorCNT[i]>0)
  162.         {
  163.          MotorCNT[i]--;
  164.          if(MotorCNT[i]==0) MotorOnOff(i,0);
  165.         }
  166.       }
  167.     }
  168.    if(app!=NULL)
  169.     {
  170.      if(Signale & AppSignalMask)
  171.       {
  172.        AppMessage=GetMsg(app->Port);
  173.        if(AppMessage!=NULL)
  174.         {
  175.          ReplyMsg(AppMessage);
  176.          bool=EinstellungenAendern();
  177.         }
  178.       }
  179.     }
  180.   }
  181.  CloseAll();
  182. }
  183.  
  184.  
  185. /* PC-Befehle ausführen */
  186. VOID HandleInt()
  187. {
  188.  UWORD i,l;
  189.  
  190.  switch(jhword->Arg1)
  191.   {
  192.    case 1234:
  193.      printf("> %ld %ld %ld\n",jhword->Arg2,jhword->Arg3,jhword->Arg4);
  194.     break;
  195.    case 1:
  196.      if(ud[Active].File==FALSE)
  197.       {
  198.        MotorCNT[Active]=ud[Active].Motor;
  199.        td[Active].Request->io_Data=mem;
  200.        l=jhword->Arg2*512;
  201.        if(ud[Active].DeviceType!=AMIGA)
  202.         CopyMemQuick(&jhbyte->Memory,mem,l);
  203.        else
  204.         CopyMemQuick(&jhword->Memory,mem,l);
  205.        td[Active].Request->io_Data=mem;
  206.        td[Active].Request->io_Length=l;
  207.        td[Active].Request->io_Offset=jhword->Arg3*512;
  208.        td[Active].Request->io_Command=CMD_WRITE;
  209.        i=DoIO(td[Active].Request);
  210.        if(i!=0)
  211.         {
  212.          switch(i)
  213.           {
  214.            case 28:
  215.              jhword->Arg2=0+BIT15;
  216.             break;
  217.        /*  case 29:
  218.              jhword->Arg2=15+BIT15;
  219.             break;  */
  220.            default:
  221.              jhword->Arg2=10+BIT15;
  222.             break;
  223.           }
  224.         }
  225.        else
  226.         {
  227.          jhword->Arg2=0;
  228.         }
  229.       }
  230.      else
  231.       {
  232.        l=jhword->Arg2*512;
  233.        Seek(td[Active].FileHandle,jhword->Arg3*512,OFFSET_BEGINNING);
  234.        i=Write(td[Active].FileHandle,&jhbyte->Memory,l);
  235.        if(i==l)
  236.         {
  237.          jhword->Arg2=0;
  238.         }
  239.        else
  240.         {
  241.          jhword->Arg2=10+BIT15;
  242.         }
  243.       }
  244.     break;
  245.    case 2:
  246.      if(ud[Active].File==FALSE)
  247.       {
  248.        MotorCNT[Active]=ud[Active].Motor;
  249.        td[Active].Request->io_Data=mem;
  250.        l=jhword->Arg2*512;
  251.        td[Active].Request->io_Length=l;
  252.        td[Active].Request->io_Offset=jhword->Arg3*512;
  253.        td[Active].Request->io_Command=CMD_READ;
  254.        i=DoIO(td[Active].Request);
  255.        if(i!=0)
  256.         {
  257.          switch(i)
  258.           {
  259.        /*  case 29:
  260.              jhword->Arg2=15+BIT15;
  261.             break;  */
  262.            default:
  263.              jhword->Arg2=11+BIT15;
  264.             break;
  265.           }
  266.         }
  267.        else
  268.         {
  269.          if(ud[Active].DeviceType!=AMIGA)
  270.           CopyMemQuick(mem,&jhbyte->Memory,l);
  271.          else
  272.           CopyMemQuick(mem,&jhword->Memory,l);
  273.          jhword->Arg2=0;
  274.         }
  275.       }
  276.      else
  277.       {
  278.        l=jhword->Arg2*512;
  279.        Seek(td[Active].FileHandle,jhword->Arg3*512,OFFSET_BEGINNING);
  280.        i=Read(td[Active].FileHandle,&jhbyte->Memory,l);
  281.        if(i==l)
  282.         {
  283.          jhword->Arg2=0;
  284.         }
  285.        else
  286.         {
  287.          jhword->Arg2=11+BIT15;
  288.         }
  289.       }
  290.     break;
  291.    case 3:
  292.      if(ud[Active].File==FALSE)
  293.       {
  294.        MotorCNT[Active]=ud[Active].Motor;
  295.        td[Active].Request->io_Command=CMD_UPDATE;
  296.        i=DoIO(td[Active].Request);
  297.        if(i!=0)
  298.         {
  299.          switch(i)
  300.           {
  301.            case 28:
  302.              jhword->Arg2=0+BIT15;
  303.             break;
  304.        /*  case 29:
  305.              jhword->Arg2=15+BIT15;
  306.             break;  */
  307.            default:
  308.              jhword->Arg2=10+BIT15;
  309.             break;
  310.           }
  311.         }
  312.        else
  313.         {
  314.          jhword->Arg2=0;
  315.         }
  316.       }
  317.     break;
  318.    case 4:
  319.      if(ud[Active].File==FALSE)
  320.       {
  321.        jhword->Arg2=ChangeCheck(Active);
  322.       }
  323.      else
  324.       {
  325.        jhword->Arg2=1;
  326.       }
  327.     break;
  328.    case 5:
  329.      jhword->Arg2=ud[Active].Tracks*ud[Active].Heads*ud[Active].SectorsPerTrack;
  330.      jhword->Arg3=ud[Active].Tracks;
  331.      jhword->Arg4=ud[Active].Heads;
  332.      CalcFAT(Active);
  333.      if(ud[Active].File==FALSE) jhword->Arg7=ud[Active].DeviceType; else jhword->Arg7=1000;
  334.     break;
  335.    case 6:
  336.      for(i=0;i<8;i++)
  337.       {
  338.        MotorOnOff(i,1);
  339.       }
  340.     break;
  341.    case 10:
  342.      Format();
  343.     break;
  344.    case 20:
  345.      Kopiere();
  346.     break;
  347.    case 100:
  348.      if(td[jhword->Arg2].Valid==FALSE)
  349.       {
  350.        jhword->Arg2=2+BIT15;
  351.       }
  352.      else
  353.       {
  354.        Active=jhword->Arg2;
  355.        jhword->Arg2=0;
  356.       }
  357.     break;
  358.    default:
  359.     break;
  360.   }
  361.  SendJanusInt(29);
  362. }
  363.  
  364.  
  365. /* Diskettenwechsel prüfen */
  366. WORD ChangeCheck(num)
  367.  UWORD num;
  368. {
  369.  REGISTER LONG i;
  370.  
  371.  td[num].Request->io_Command=TD_CHANGENUM;
  372.  DoIO(td[num].Request);
  373.  i=td[num].Request->io_Actual;
  374.  if(i!=td[num].Changes)
  375.   {
  376.    td[num].Changes=i;
  377.    return(0xFF);
  378.   }
  379.  return(1);
  380. }
  381.  
  382.  
  383. /* Laufwerke öffnen */
  384. VOID InstallAll()
  385. {
  386.  REGISTER LONG i;
  387.  
  388.  for(i=0;i<8;i++)
  389.   {
  390.    if(ud[i].File==FALSE)
  391.     {
  392.      InstallDevice(i);
  393.     }
  394.    else
  395.     {
  396.      InstallFile(i);
  397.     }
  398.   }
  399. }
  400.  
  401.  
  402. /* Laufwerke schließen */
  403. VOID UninstallAll()
  404. {
  405.  REGISTER LONG i;
  406.  
  407.  for(i=0;i<8;i++)
  408.   {
  409.    if(ud[i].File==FALSE)
  410.     {
  411.      UninstallDevice(i);
  412.     }
  413.    else
  414.     {
  415.      UninstallFile(i);
  416.     }
  417.   }
  418. }
  419.  
  420.  
  421. VOID InstallDevice(num)
  422.  UWORD num;
  423. {
  424.  
  425.  td[num].Port=CreatePort(0L,0L);
  426.  if(td[num].Port!=NULL)
  427.   {
  428.    td[num].Request=CreateExtIO(td[num].Port,200);
  429.    if(td[num].Request!=NULL)
  430.     {
  431.      td[num].Device=OpenDevice(&ud[num].Name,ud[num].Unit,td[num].Request,0);
  432.      if(td[num].Device!=0)
  433.       {
  434.        UninstallDevice(num);
  435.       }
  436.     }
  437.    else
  438.     {
  439.      UninstallDevice(num);
  440.     }
  441.   }
  442.  else
  443.   {
  444.    UninstallDevice(num);
  445.   }
  446. }
  447.  
  448.  
  449. VOID UninstallDevice(num)
  450.  UWORD num;
  451. {
  452.  
  453.  if(td[num].Valid==TRUE)
  454.   {
  455.    if(td[num].Device==0L) CloseDevice(td[num].Request);
  456.    if(td[num].Request) DeleteExtIO(td[num].Request);
  457.    if(td[num].Port) DeletePort(td[num].Port);
  458.    td[num].Valid=FALSE;
  459.   }
  460. }
  461.  
  462.  
  463. /* Datei installieren */
  464. VOID InstallFile(num)
  465.  UWORD num;
  466. {
  467.  REGISTER ULONG            i,j;
  468.  register struct FileLock *lock;
  469.  
  470.  td[num].Valid=FALSE;
  471.  lock=Lock(&ud[num].Name,ACCESS_READ);
  472.  if(lock!=NULL)
  473.   {
  474.    UnLock(lock);
  475.    td[num].FileHandle=Open(&ud[num].Name,MODE_READWRITE);
  476.    if(td[num].FileHandle!=NULL)
  477.     {
  478.      Seek(td[num].FileHandle,0,OFFSET_END);
  479.      i=Seek(td[num].FileHandle,0,OFFSET_BEGINNING);
  480.      j=512L*(ULONG)ud[num].Tracks*(ULONG)ud[num].Heads*(ULONG)ud[num].SectorsPerTrack;
  481.      if(i!=j)
  482.       {
  483.        MultiRequest("Inkompatible Dateilänge bei LW-Datei",&ud[num].Name,"Okay",NULL);
  484.        Close(td[num].FileHandle);
  485.       }
  486.      else
  487.       {
  488.        td[num].Valid=TRUE;
  489.       }
  490.     }
  491.   }
  492. }
  493.  
  494.  
  495. VOID UninstallFile(num)
  496.  UWORD num;
  497. {
  498.  
  499.  if(td[num].Valid==TRUE)
  500.   {
  501.    if(td[num].FileHandle) Close(td[num].FileHandle);
  502.    td[num].Valid=FALSE;
  503.   }
  504. }
  505.  
  506.  
  507. /* Installationsroutine */
  508. VOID OpenAll()
  509. {
  510.  REGISTER UWORD              i;
  511.  register struct MsgPort    *p;
  512.  register struct FileHandle *fh;
  513.  
  514.  ATUtilitiesBase=OpenLibrary("at-utilities.library",0L);
  515.  if(ATUtilitiesBase==NULL)
  516.   {
  517.    printf("Kann ATUtilities-Library nicht öffnen.\n");
  518.    CloseAll();
  519.   }
  520.  
  521.  GfxBase=OpenLibrary("graphics.library",0L);
  522.  IntuitionBase=OpenLibrary("intuition.library",0L);
  523.  if((GfxBase==NULL)||(IntuitionBase==NULL))
  524.   {
  525.    CloseAll();
  526.   }
  527.  
  528.  p=FindPort(TransferPort);
  529.  if(p!=NULL)
  530.   {
  531.    InfoRequest("ATUtilities Disk Transfer ist schon aktiv.");
  532.    CloseAll();
  533.   }
  534.  
  535.  MainTask=FindTask(NULL);
  536.  SetTaskPri(MainTask,10);
  537.  
  538.  JanusBase=OpenLibrary("janus.library",0L);
  539.  if(JanusBase==NULL)
  540.   {
  541.    ErrorRequest(ERROR_JANUS);
  542.    CloseAll();
  543.   }
  544.  
  545.  TaskSignal=AllocSignal(-1L);
  546.  if(TaskSignal==-1L)
  547.   {
  548.    ErrorRequest(ERROR_SIGNAL);
  549.    CloseAll();
  550.   }
  551.  
  552.  Port=CreatePort(TransferPort,0L);
  553.  if(Port==NULL)
  554.   {
  555.    ErrorRequest(ERROR_MPORT);
  556.    CloseAll();
  557.   }
  558.  
  559.  fh=Open(PrefsName,MODE_OLDFILE);
  560.  if(fh!=NULL)
  561.   {
  562.    Read(fh,&ud,sizeof(struct UDevice)*8);
  563.    Close(fh);
  564.   }
  565.  
  566.  InstallAll();
  567.  
  568.  mem=AllocMem(PUBLIC_PAGESIZE,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  569.  if(mem==NULL)
  570.   {
  571.    ErrorRequest(ERROR_ALLOC);
  572.    CloseAll();
  573.   }
  574.  
  575.  ExtSetupSig=CreatePublicHandler(29);
  576.  if(ExtSetupSig==NULL)
  577.   {
  578.    CloseAll();
  579.   }
  580.  
  581.  TaskPort=CreatePort("Disk Transfer Motor Task <Stop>",0L);
  582.  ReplyPort=CreatePort("Disk Transfer <Stop> Reply",0L);
  583.  if((TaskPort==NULL)||(ReplyPort==NULL))
  584.   {
  585.    ErrorRequest(ERROR_PORT);
  586.    CloseAll();
  587.   }
  588.  
  589.  MotorTask=CreateProcess(Motor,500,"Disk Transfer Motor Task",2);
  590.  if(MotorTask==NULL)
  591.   {
  592.    DeletePort(TaskPort);
  593.    InfoRequest("Kann Motor-Task nicht erstellen.\n");
  594.    CloseAll();
  595.   }
  596.  
  597.  app=CreateAppItem("ATUtilities Disk Transfer");
  598.  if(app!=NULL) AppSignalMask=app->SignalMask; else AppSignalMask=0;
  599.  
  600.  jhword=ExtSetupSig->WordAccess;
  601.  jhbyte=ExtSetupSig->ByteAccess;
  602.  PortSignal=Port->mp_SigBit;
  603.  PortSignalMask=(1L<<PortSignal);
  604.  JanusSignal=ExtSetupSig->JanusSignal;
  605.  JanusSignalMask=ExtSetupSig->JanusSignalMask;
  606.  TaskSignalMask=(1L<<TaskSignal);
  607.  WaitSignalMask=PortSignalMask+JanusSignalMask+TaskSignalMask+AppSignalMask;
  608. }
  609.  
  610.  
  611. /* Programmende */
  612. VOID CloseAll()
  613. {
  614.  if(app) DeleteAppItem(app);
  615.  if(MotorTask!=NULL)
  616.   {
  617.    Message.mn_Node.ln_Type=NT_MESSAGE;
  618.    Message.mn_ReplyPort=ReplyPort;
  619.    PutMsg(TaskPort,&Message);
  620.    WaitPort(ReplyPort);
  621.    DeletePort(ReplyPort);
  622.   }
  623.  if(ExtSetupSig) DeletePublicHandler(ExtSetupSig);
  624.  if(mem) FreeMem(mem,PUBLIC_PAGESIZE);
  625.  if(TaskSignal!=-1) FreeSignal(TaskSignal);
  626.  if(Port) DeletePort(Port);
  627.  UninstallAll();
  628.  if(ATUtilitiesBase) CloseLibrary(ATUtilitiesBase);
  629.  if(GfxBase) CloseLibrary(GfxBase);
  630.  if(IntuitionBase) CloseLibrary(IntuitionBase);
  631.  if(JanusBase) CloseLibrary(JanusBase);
  632.  exit(0);
  633. }
  634.  
  635.  
  636. /* Einstellungs-Fenster */
  637. BOOL EinstellungenAendern()
  638. {
  639.  UBYTE                        text[40];
  640.  BOOL                         bool,ende;
  641.  REGISTER ULONG               Class;
  642.  REGISTER WORD                i,j,id;
  643.  register struct Window       *win;
  644.  register struct RastPort     *rp;
  645.  register struct Gadget       *gad;
  646.  register struct IntuiMessage *msg;
  647.  register struct TextFont     *opal;
  648.  
  649.  win=CreateStdWindow("ATUtilities - Disk Transfer Einstellungen",
  650.                      75,75,460,142+BorderHeight(),CLOSEWINDOW|GADGETUP,
  651.                      ACTIVATE|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE|GIMMEZEROZERO);
  652.  ende=FALSE;
  653.  if(win!=NULL)
  654.   {
  655.    rp=win->RPort;
  656.    opal=GetOpalFont();
  657.    SetFont(rp,opal);
  658.  
  659.    CreateBoolGadget(win,10,5,155,12,"Einstellungen Okay",1);
  660.    CreateBoolGadget(win,170,5,155,12,"Programm beenden",2);
  661.    CreateBoolGadget(win,335,5,50,12,"Info",3);
  662.    CreateBoolGadget(win,390,5,50,12,"Hilfe",4);
  663.    for(i=0,j=10;i<8;i++,j++)
  664.     {
  665.      sprintf(&text,"Laufwerk %ld:",i+1);
  666.      CreateBoolGadget(win,33,25+(i*14),120,12,&text,j);
  667.      CreateBoolGadget(win,10,25+(i*14),20,12,"!",i+100);
  668.      ZeigeLW(rp,i);
  669.     }
  670.  
  671.    bool=FALSE;
  672.    while(bool==FALSE)
  673.     {
  674.      WaitPort(win->UserPort);
  675.      msg=GetMsg(win->UserPort);
  676.      Class=msg->Class;
  677.      gad=msg->IAddress;
  678.      ReplyMsg(msg);
  679.      switch(Class)
  680.       {
  681.        case GADGETUP:
  682.          id=gad->GadgetID;
  683.          switch(id)
  684.           {
  685.            case 1:
  686.              bool=TRUE;
  687.             break;
  688.            case 2:
  689.              ende=TRUE; bool=TRUE;
  690.             break;
  691.            case 3:
  692.              ShowInfo();
  693.             break;
  694.            case 4:
  695.              Help(HelpName,0);
  696.             break;
  697.            default:
  698.              if((id>=10)&&(id<=17))
  699.               {
  700.                j=id-10;
  701.                EditiereLW(j);
  702.                ZeigeLW(rp,j);
  703.               }
  704.              if((id>=100)&&(id<=107))
  705.               {
  706.                j=id-100;
  707.                if(ud[j].File==FALSE)
  708.                 {
  709.                  if(td[j].Valid==TRUE)
  710.                   {
  711.                    Bearbeite(j);
  712.                   }
  713.                  else
  714.                   {
  715.                    MultiRequest("Dieses Device ist nocht nicht verfügbar.",
  716.                                 "Bitte prüfen Sie die Einstellungen.","Okay",0L);
  717.                   }
  718.                 }
  719.                else
  720.                 {
  721.                  BearbeiteFile(j);
  722.                 }
  723.               }
  724.             break;
  725.           }
  726.         break;
  727.        case CLOSEWINDOW:
  728.          bool=TRUE;
  729.         break;
  730.       }
  731.     }
  732.  
  733.    DeleteStdWindow(win);
  734.   }
  735.  if(ende) ende=ExitWarning();
  736.  return(ende);
  737. }
  738.  
  739.  
  740. VOID Type(win,typ)
  741.  struct Window *win;
  742.  UWORD          typ;
  743. {
  744.  REGISTER UBYTE *txt;
  745.  
  746.  switch(typ)
  747.   {
  748.    case AMIGA:
  749.      txt="Normal";
  750.     break;
  751.    case PC720K:
  752.      txt="720K DD";
  753.     break;
  754.    case PC144M:
  755.      txt="1.44M HD";
  756.     break;
  757.    default:
  758.      txt="Datei";
  759.     break;
  760.   }
  761.  DrawCNTextBorder(win,280,5,100,12,txt);
  762. }
  763.  
  764. /* Parameter ändern */
  765. VOID EditiereLW(num)
  766.  UWORD num;
  767. {
  768.  UBYTE                         text[10];
  769.  BOOL                          ende,f;
  770.  ULONG                         a,b,c,d;
  771.  UWORD                         typ;
  772.  REGISTER ULONG                Class;
  773.  REGISTER WORD                 i,j,id;
  774.  UBYTE                        *bDevice,
  775.                               *bUnit,
  776.                               *bBlocksPerTrack,
  777.                               *bTracks,
  778.                               *bHeads,
  779.                               *bMotor;
  780.  register struct Window       *win;
  781.  register struct RastPort     *rp;
  782.  register struct IntuiMessage *msg;
  783.  register struct TextFont     *opal;
  784.  register struct Gadget       *gad,*isFile;
  785.  struct FileHandle            *fh;
  786.  
  787.  win=CreateStdWindow("Laufwerksparameter editieren",
  788.                      225,90,410,100+BorderHeight(),CLOSEWINDOW|GADGETUP,
  789.                      ACTIVATE|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE|GIMMEZEROZERO);
  790.  ende=FALSE;
  791.  if(win!=NULL)
  792.   {
  793.    rp=win->RPort;
  794.    opal=GetOpalFont();
  795.    SetFont(rp,opal);
  796.  
  797.    CreateBoolGadget(win,10,5,100,12,"Okay",1);
  798.    CreateBoolGadget(win,120,5,100,12,"Abbruch",2);
  799.  
  800.    CreateBoolGadget(win,250,5,25,12,"»",100);
  801.    if(ud[num].File==TRUE)
  802.     typ=1000;
  803.    else
  804.     typ=ud[num].DeviceType;
  805.    Type(win,typ);
  806.  
  807.    bDevice=CreateStringGadget(win,120,20,260,10,&ud[num].Name,100,3);
  808.    sprintf(&text,"%ld",ud[num].Unit);
  809.    bUnit=CreateIntegerGadget(win,120,35,60,10,&text,4,4);
  810.    sprintf(&text,"%ld",ud[num].Heads);
  811.    bHeads=CreateIntegerGadget(win,320,35,60,10,&text,5,5);
  812.    sprintf(&text,"%ld",ud[num].Tracks);
  813.    bTracks=CreateIntegerGadget(win,120,47,60,10,&text,7,6);
  814.    sprintf(&text,"%ld",ud[num].SectorsPerTrack);
  815.    bBlocksPerTrack=CreateIntegerGadget(win,320,47,60,10,&text,5,7);
  816.    sprintf(&text,"%ld",ud[num].Motor);
  817.    bMotor=CreateIntegerGadget(win,320,64,60,10,&text,5,8);
  818.  
  819.    WriteText(rp,15,27,"Device/Datei:");
  820.    WriteText(rp,15,42,"Unit:");
  821.    WriteText(rp,220,42,"S/L-Köpfe:");
  822.    WriteText(rp,15,54,"Spuren:");
  823.    WriteText(rp,220,54,"Sekt./Spur:");
  824.    WriteText(rp,15,72,"Motor-Ausschaltzeit nach x Sekunden:");
  825.  
  826.    ende=FALSE;
  827.    while(ende==FALSE)
  828.     {
  829.      WaitPort(win->UserPort);
  830.      msg=GetMsg(win->UserPort);
  831.      Class=msg->Class;
  832.      gad=msg->IAddress;
  833.      ReplyMsg(msg);
  834.      switch(Class)
  835.       {
  836.        case GADGETUP:
  837.          id=gad->GadgetID;
  838.          switch(id)
  839.           {
  840.            case 100:
  841.              if(typ==1000)
  842.               typ=0;
  843.              else
  844.               typ=typ+1;
  845.              if(typ>PC144M) typ=1000;
  846.              Type(win,typ);
  847.             break;
  848.            case 2:
  849.              ende=TRUE;
  850.             break;
  851.            case 1:
  852.              j=0;
  853.              a=atol(bUnit);
  854.              b=atol(bTracks);
  855.              c=atol(bHeads);
  856.              d=atol(bBlocksPerTrack);
  857.              i=atol(bMotor);
  858.              if(isFile->Flags & SELECTED) f=TRUE; else f=FALSE;
  859.              if(b<2)
  860.               { InfoRequest("Unzulässige Spurenanzahl."); j=1; }
  861.              if(c<1)
  862.               { InfoRequest("Unzulässige S/L-Kopfanzahl."); j++; }
  863.              if(d<2)
  864.               { InfoRequest("Unzulässige Anzahl von Sektoren/Spur."); j++; }
  865.              if(i>180)
  866.               { InfoRequest("Motor-Zeit nicht empfehlenswert (>180s)."); }
  867.              if(j==0)
  868.               {
  869.                if(strcmp(&ud[num].Name,bDevice)) j=1;
  870.                if(ud[num].Unit!=a) j=1;
  871.                if(ud[num].Tracks!=b) j=1;
  872.                if(ud[num].Heads!=c) j=1;
  873.                if(ud[num].SectorsPerTrack!=d) j=1;
  874.                strcpy(&ud[num].Name,bDevice);
  875.                ud[num].Motor=i;
  876.                ud[num].Unit=a;
  877.                ud[num].Tracks=b;
  878.                ud[num].Heads=c;
  879.                ud[num].SectorsPerTrack=d;
  880.                if(typ==1000)
  881.                 ud[num].File=TRUE;
  882.                else
  883.                 {
  884.                  ud[num].File=FALSE;
  885.                  ud[num].DeviceType=typ;
  886.                 }
  887.                if(j==1)
  888.                 {
  889.                  td[num].Valid=FALSE;
  890.                  MultiRequest("Um Probleme mit MS-DOS zu vermeiden, wird",
  891.                               "das Laufwerk erst nach einem Reset aktiv.",
  892.                               "Okay",NULL);
  893.                 }
  894.                fh=Open(PrefsName,MODE_NEWFILE);
  895.                if(fh!=NULL)
  896.                 {
  897.                  Write(fh,&ud,sizeof(struct UDevice)*8);
  898.                  Close(fh);
  899.                 }
  900.                else
  901.                 {
  902.                  InfoRequest("Fehler beim Schreiben der Prefs-Datei.");
  903.                 }
  904.                ende=TRUE;
  905.               }
  906.             break;
  907.           }
  908.         break;
  909.        case CLOSEWINDOW:
  910.          ende=TRUE;
  911.         break;
  912.       }
  913.     }
  914.    DeleteStdWindow(win);
  915.   }
  916. }
  917.  
  918.  
  919. /* Parameter anzeigen */
  920. VOID ZeigeLW(rp,id)
  921.  struct RastPort *rp;
  922.  UWORD            id;
  923. {
  924.  UBYTE          size[20];
  925.  UBYTE          text[30];
  926.  REGISTER ULONG kb;
  927.  
  928.  kb=(ud[id].Heads*ud[id].Tracks*ud[id].SectorsPerTrack*512)/1024;
  929.  if(kb>=10000)
  930.   {
  931.    sprintf(&size,"%ld MB",kb/1024);
  932.   }
  933.  else
  934.   {
  935.    sprintf(&size,"%ld KB",kb);
  936.   }
  937.  if(ud[id].File==FALSE)
  938.   {
  939.    sprintf(&text,"%s  %s  Unit %ld",
  940.                   &size,&ud[id].Name,ud[id].Unit);
  941.   }
  942.  else
  943.   {
  944.    sprintf(&text,"%s  %s",&size,&ud[id].Name);
  945.   }
  946.  SetAPen(rp,0);
  947.  RectFill(rp,158,23+(id*14),450,36+(id*14));
  948.  SelectStdFPen(rp);
  949.  WriteText(rp,160,33+(id*14),&text);
  950. }
  951.  
  952.  
  953. /* Device-Laufwerk bearbeiten */
  954. VOID Bearbeite(num)
  955.  UWORD num;
  956. {
  957.  UBYTE                         text[40];
  958.  REGISTER BOOL                 ende,bool;
  959.  REGISTER ULONG                Class;
  960.  REGISTER WORD                 i,j,id;
  961.  register struct Window       *win;
  962.  register struct RastPort     *rp;
  963.  register struct Gadget       *gad;
  964.  register struct IntuiMessage *msg;
  965.  register struct TextFont     *opal;
  966.  register struct Gadget       *verify;
  967.  BOOL                          v;
  968.  ULONG                         BytesPerTrack;
  969.  ULONG                         Track;
  970.  UBYTE                        *FormatMemory;
  971.  
  972.  win=CreateStdWindow("Speichermedium bearbeiten",
  973.                      225,90,310,66+BorderHeight(),CLOSEWINDOW|GADGETUP,
  974.                      ACTIVATE|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE|GIMMEZEROZERO);
  975.  ende=FALSE;
  976.  if(win!=NULL)
  977.   {
  978.    rp=win->RPort;
  979.    opal=GetOpalFont();
  980.    SetFont(rp,opal);
  981.  
  982.    CreateBoolGadget(win,10,5,100,12,"Okay",1);
  983.    CreateBoolGadget(win,10,20,119,12,"Hard-Format",2);
  984.    CreateBoolGadget(win,10,34,172,12,"Prüfe auf Fehler",3);
  985.    verify=CreateSToggleGadget(win,132,20,50,12,"Verify",100);
  986.    DrawNTextBorder(win,10,48,280,12,"Kein Fehler aufgetreten.");
  987.    DrawNTextBorder(win,190,20,100,12,"0");
  988.    DrawNTextBorder(win,190,34,100,12,"0 %");
  989.  
  990.    ende=FALSE;
  991.    while(ende==FALSE)
  992.     {
  993.      WaitPort(win->UserPort);
  994.      msg=GetMsg(win->UserPort);
  995.      Class=msg->Class;
  996.      gad=msg->IAddress;
  997.      ReplyMsg(msg);
  998.      switch(Class)
  999.       {
  1000.        case GADGETUP:
  1001.          id=gad->GadgetID;
  1002.          switch(id)
  1003.           {
  1004.            case 2:
  1005.            case 3:
  1006.              DrawCNTextBorder(win,10,48,280,12,"Kein Fehler aufgetreten.");
  1007.              if(verify->Flags & SELECTED) v=TRUE; else v=FALSE;
  1008.              if(id==3)
  1009.               {
  1010.                bool=MultiRequest("Wollen Sie den Datenträger auf",
  1011.                                  "Fehler überprüfen ?",
  1012.                                  "Ja, Prüfen","Nein, Zurück");
  1013.               }
  1014.              else
  1015.               {
  1016.                bool=MultiRequest("Hard-Format: Alle Daten werden gelöscht!",
  1017.                                  "Sind Sie wirklich sicher ?",
  1018.                                  "Ja, Format","NEIN! Zurück");
  1019.               }
  1020.              if(bool==TRUE)
  1021.               {
  1022.                MotorCNT[num]=5;
  1023.                BytesPerTrack=ud[num].SectorsPerTrack*ud[num].Heads*512;
  1024.                FormatMemory=AllocMem(BytesPerTrack,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  1025.                if(FormatMemory!=NULL)
  1026.                 {
  1027.                  SetDrMd(rp,JAM2);
  1028.                  j=0;
  1029.                  for(Track=0;Track<ud[num].Tracks;Track++)
  1030.                   {
  1031.                    sprintf(&text,"   %ld   ",Track);
  1032.                    DrawNTextBorder(win,190,20,100,12,&text);
  1033.                    sprintf(&text,"   %3ld %%   ",((Track*100)/(ud[num].Tracks-1)));
  1034.                    DrawNTextBorder(win,190,34,100,12,&text);
  1035.                    if(ud[num].File==FALSE)
  1036.                     {
  1037.                      if(id==3)
  1038.                       {
  1039.                        td[num].Request->io_Data=FormatMemory;
  1040.                        td[num].Request->io_Length=BytesPerTrack;
  1041.                        td[num].Request->io_Offset=Track*BytesPerTrack;
  1042.                        td[num].Request->io_Command=CMD_READ;
  1043.                        i=DoIO(td[num].Request);
  1044.                        if(i!=0)
  1045.                         {
  1046.                          if(i==29)
  1047.                           {
  1048.                            InfoRequest("Das Medium ist nicht eingelegt.");
  1049.                            Track=ud[num].Tracks;
  1050.                           }
  1051.                          else
  1052.                           {
  1053.                            sprintf(&text,"Fehler #%ld auf Track %ld.",i,Track);
  1054.                            DrawCNTextBorder(win,10,48,280,12,&text);
  1055.                           }
  1056.                          j++;
  1057.                         }
  1058.                       }
  1059.                      else
  1060.                       {
  1061.                        td[num].Request->io_Data=FormatMemory;
  1062.                        td[num].Request->io_Length=BytesPerTrack;
  1063.                        td[num].Request->io_Offset=Track*BytesPerTrack;
  1064.                        td[num].Request->io_Command=TD_FORMAT;
  1065.                        i=DoIO(td[num].Request);
  1066.                        if(i!=0)
  1067.                         {
  1068.                          sprintf(&text,"Format: Fehler #%ld auf Track %ld.",i,Track);
  1069.                          DrawCNTextBorder(win,10,48,280,12,&text);
  1070.                          j++;
  1071.                          if(i==28)
  1072.                           {
  1073.                            InfoRequest("Das Medium ist schreibgeschützt.");
  1074.                            Track=ud[num].Tracks;
  1075.                           }
  1076.                          else if(i==29)
  1077.                           {
  1078.                            InfoRequest("Das Medium ist nicht eingelegt.");
  1079.                            Track=ud[num].Tracks;
  1080.                           }
  1081.                         }
  1082.                        if((v==TRUE)&&(Track<ud[num].Tracks))
  1083.                         {
  1084.                          td[num].Request->io_Data=FormatMemory;
  1085.                          td[num].Request->io_Length=BytesPerTrack;
  1086.                          td[num].Request->io_Offset=Track*BytesPerTrack;
  1087.                          td[num].Request->io_Command=CMD_READ;
  1088.                          i=DoIO(td[num].Request);
  1089.                          if(i!=0)
  1090.                           {
  1091.                            sprintf(&text,"Verify: Fehler #%ld auf Track %ld.",i,Track);
  1092.                            DrawCNTextBorder(win,10,48,280,12,&text);
  1093.                            j++;
  1094.                           }
  1095.                         }
  1096.                       }
  1097.                     }
  1098.                   }
  1099.                  if(j==0)
  1100.                   {
  1101.                    if(id==3) InfoRequest("Der Datenträger ist fehlerfrei.");
  1102.                   }
  1103.                  else
  1104.                   {
  1105.                    if(id==3)
  1106.                     {
  1107.                      sprintf(&text,"%ld Fehler gefunden worden.",j);
  1108.                      MultiRequest("Bei der Überprüfung sind",&text,"Okay",NULL);
  1109.                     }
  1110.                    else
  1111.                     {
  1112.                      sprintf(&text,"%ld Fehler aufgetreten.",j);
  1113.                      MultiRequest("Bei der Formatierung sind",&text,"Okay",NULL);
  1114.                     }
  1115.                   }
  1116.                  FreeMem(FormatMemory,BytesPerTrack);
  1117.                 }
  1118.               }
  1119.             break;
  1120.            case 1:
  1121.              ende=TRUE;
  1122.             break;
  1123.           }
  1124.         break;
  1125.        case CLOSEWINDOW:
  1126.          ende=TRUE;
  1127.         break;
  1128.       }
  1129.     }
  1130.    DeleteStdWindow(win);
  1131.   }
  1132. }
  1133.  
  1134.  
  1135. /* FAT berechnen */
  1136. VOID CalcFAT(num)
  1137.  UWORD num;
  1138. {
  1139.  REGISTER UWORD anz,i;
  1140.  REGISTER ULONG bytes,plus,sek,spc;
  1141.  
  1142.  
  1143.  sek=ud[num].Tracks*ud[num].Heads*ud[num].SectorsPerTrack;
  1144.  if(sek>4096)
  1145.   {
  1146.    bytes=sek*2;       /* FAT 16-Bit */
  1147.   }
  1148.  else
  1149.   {
  1150.    bytes=(sek*3)/2;   /* FAT 12-Bit */
  1151.   }
  1152.  plus=0;
  1153.  anz=0;
  1154.  for(i=0;i<32000;i++)
  1155.   {
  1156.    if(plus>=bytes)
  1157.     {
  1158.      spc=1;
  1159.      if(anz>15)
  1160.       {
  1161.        do
  1162.         {
  1163.          spc=spc*2;
  1164.          anz=anz/2;
  1165.         } while(anz>15);
  1166.       }
  1167.      jhword->Arg5=anz;
  1168.      jhbyte->Arg6=spc;
  1169.      return;
  1170.     }
  1171.    else
  1172.     {
  1173.      plus+=512;
  1174.      anz++;
  1175.     }
  1176.   }
  1177. }
  1178.  
  1179.  
  1180. /* File-Laufwerk bearbeiten */
  1181. VOID BearbeiteFile(num)
  1182.  UWORD num;
  1183. {
  1184.  UBYTE                       text[35];
  1185.  REGISTER BOOL               bool;
  1186.  REGISTER UBYTE             *mem;
  1187.  REGISTER ULONG              i,j,k,l;
  1188.  register struct FileHandle *fh;
  1189.  register struct Window     *win;
  1190.  register struct RastPort   *rp;
  1191.  struct TextFont            *opal;
  1192.  struct IntuiMessage        *msg;
  1193.  
  1194.  if(td[num].Valid==FALSE)
  1195.   {
  1196.    bool=MultiRequest("Es existiert keine Laufwerksdatei.",
  1197.                      "Möchten Sie eine erstellen ?",
  1198.                      "Ja, Erstellen","Nein, Zurück");
  1199.    if(bool==TRUE)
  1200.     {
  1201.      j=512*ud[num].SectorsPerTrack*ud[num].Heads;
  1202.      mem=AllocMem(j,MEMF_CLEAR|MEMF_PUBLIC);
  1203.      if(mem!=NULL)
  1204.       {
  1205.        fh=Open(&ud[num].Name,MODE_NEWFILE);
  1206.        if(fh!=NULL)
  1207.         {
  1208.          win=CreateStdWindow("Laufwerksdatei erstellen",
  1209.                              75,90,310,30+BorderHeight(),GADGETUP|CLOSEWINDOW,
  1210.                              WINDOWCLOSE|WINDOWDEPTH|ACTIVATE|WINDOWDRAG|GIMMEZEROZERO);
  1211.          if(win!=NULL)
  1212.           {
  1213.            opal=GetOpalFont();
  1214.            rp=win->RPort;
  1215.            SetFont(rp,opal);
  1216.            CreateBoolGadget(win,10,5,120,12,"Stop!",1);
  1217.            bool=FALSE;
  1218.            if(win!=NULL)
  1219.             {
  1220.              for(i=0;i<ud[num].Tracks;i++)
  1221.               {
  1222.                sprintf(&text,"Track %ld von %ld",i,ud[num].Tracks);
  1223.                DrawCNTextBorder(win,140,5,150,12,&text);
  1224.                k=Write(fh,mem,j);
  1225.                if(k!=j)
  1226.                 {
  1227.                  InfoRequest("Schreibfehler!");
  1228.                  i=ud[num].Tracks;
  1229.                  bool=TRUE;
  1230.                 }
  1231.                msg=GetMsg(win->UserPort);
  1232.                if(msg!=NULL)
  1233.                 {
  1234.                  InfoRequest("Stop!");
  1235.                  i=ud[num].Tracks;
  1236.                  bool=TRUE;
  1237.                 }
  1238.               }
  1239.              if(bool==FALSE)
  1240.               {
  1241.                td[num].FileHandle=fh;
  1242.                td[num].Valid=TRUE;
  1243.               }
  1244.              else
  1245.               {
  1246.                Close(fh);
  1247.                DeleteFile(&ud[num].Name);
  1248.               }
  1249.             }
  1250.            DeleteStdWindow(win);
  1251.           }
  1252.          else
  1253.           {
  1254.            Close(fh);
  1255.            DeleteFile(&ud[num].Name);
  1256.            ErrorRequest(ERROR_ALLOC);
  1257.           }
  1258.         }
  1259.        else InfoRequest("Laufwerksdatei läßt sich nicht erstellen.");
  1260.        FreeMem(mem,j);
  1261.       }
  1262.      else ErrorRequest(ERROR_ALLOC);
  1263.     }
  1264.   }
  1265.  else
  1266.   {
  1267.    win=CreateStdWindow("Laufwerksdatei-Information",75,90,310,70+BorderHeight(),
  1268.                        CLOSEWINDOW|GADGETUP,
  1269.                        WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|ACTIVATE|GIMMEZEROZERO);
  1270.    if(win!=NULL)
  1271.     {
  1272.      opal=GetOpalFont();
  1273.      rp=win->RPort;
  1274.      SetFont(rp,opal);
  1275.      CreateBoolGadget(win,10,5,120,12,"Okay",1);
  1276.  
  1277.      sprintf(&text,"Spuren: %ld",ud[num].Tracks);
  1278.      DrawNTextBorder(win,10,20,280,12,&text);
  1279.      sprintf(&text,"S/L-Köpfe: %ld",ud[num].Heads);
  1280.      DrawNTextBorder(win,10,35,280,12,&text);
  1281.      sprintf(&text,"Sektoren/Spur: %ld",ud[num].SectorsPerTrack);
  1282.      DrawNTextBorder(win,10,50,280,12,&text);
  1283.      sprintf(&text,"KBytes: %ld",(ud[num].Tracks*ud[num].SectorsPerTrack*ud[num].Heads)/2);
  1284.      DrawNTextBorder(win,10,65,280,12,&text);
  1285.  
  1286.      WaitPort(win->UserPort);
  1287.      DeleteStdWindow(win);
  1288.     }
  1289.   }
  1290. }
  1291.  
  1292.  
  1293. /* Motor-Kontrollprozeß */
  1294. VOID Motor()
  1295. {
  1296.  register struct Message *msg;
  1297.  
  1298.  geta4();
  1299.  do
  1300.   {
  1301.    Delay(50);
  1302.    Signal(MainTask,TaskSignalMask);
  1303.    msg=GetMsg(TaskPort);
  1304.   }
  1305.  while(msg==NULL);
  1306.  DeletePort(TaskPort);
  1307.  ReplyMsg(msg);
  1308.  Exit(0);
  1309. }
  1310.  
  1311.  
  1312. /* Motor ein- und ausschalten */
  1313. VOID MotorOnOff(num,status)
  1314.  UWORD num;
  1315.  UWORD status;
  1316. {
  1317.  
  1318.  if(td[num].Valid==TRUE)
  1319.   {
  1320.    if(ud[num].File==FALSE)
  1321.     {
  1322.      td[num].Request->io_Command=TD_MOTOR;
  1323.      td[num].Request->io_Length=status;
  1324.      SendIO(td[num].Request);
  1325.      if(status) MotorCNT[num]=ud[num].Motor;
  1326.     }
  1327.   }
  1328. }
  1329.  
  1330.  
  1331. /* Datenträger formatieren */
  1332. VOID Format()
  1333. {
  1334.  REGISTER ULONG  tSize;
  1335.  REGISTER UBYTE *fBuffer;
  1336.  REGISTER UWORD  res,i;
  1337.  
  1338.  res=0;
  1339.  if(ud[Active].File==FALSE)
  1340.   {
  1341.    tSize=512*ud[Active].SectorsPerTrack*ud[Active].Heads;
  1342.    fBuffer=AllocMem(tSize,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  1343.    if(fBuffer!=NULL)
  1344.     {
  1345.      td[Active].Request->io_Data=fBuffer;
  1346.      td[Active].Request->io_Length=tSize;
  1347.      td[Active].Request->io_Offset=jhword->Arg2*tSize;
  1348.      td[Active].Request->io_Command=TD_FORMAT;
  1349.      i=DoIO(td[Active].Request);
  1350.      if(i==0)
  1351.       {
  1352.        if(jhword->Arg3==1)
  1353.         {
  1354.          td[Active].Request->io_Command=CMD_READ;
  1355.          i=DoIO(td[Active].Request);
  1356.          if(i!=0) res=3;
  1357.         }
  1358.       } else res=2;
  1359.      MotorCNT[Active]=ud[Active].Motor;
  1360.      FreeMem(fBuffer,tSize);
  1361.     }
  1362.    else res=1;
  1363.   }
  1364.  jhword->Arg2=res;
  1365. }
  1366.  
  1367.  
  1368. /* Datenträger kopieren */
  1369. VOID Kopiere()
  1370. {
  1371.  REGISTER ULONG  tSize;
  1372.  REGISTER UBYTE *fBuffer;
  1373.  REGISTER UWORD  res,i;
  1374.  
  1375.  res=0;
  1376.  tSize=512*ud[Active].SectorsPerTrack*ud[Active].Heads;
  1377.  fBuffer=AllocMem(tSize,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  1378.  if(fBuffer!=NULL)
  1379.   {
  1380.    if(ud[Active].File==FALSE)
  1381.     {
  1382.      td[Active].Request->io_Data=fBuffer;
  1383.      td[Active].Request->io_Length=tSize;
  1384.      td[Active].Request->io_Offset=jhword->Arg2*tSize;
  1385.      td[Active].Request->io_Command=CMD_READ;
  1386.      i=DoIO(td[Active].Request);
  1387.     }
  1388.    else
  1389.     {
  1390.      Seek(td[Active].FileHandle,jhword->Arg2*tSize,OFFSET_BEGINNING);
  1391.      i=Read(td[Active].FileHandle,fBuffer,tSize);
  1392.      if(i!=tSize) i=1; else i=0;
  1393.     }
  1394.    if(i==0)
  1395.     {
  1396.      if(ud[jhword->Arg3].File==FALSE)
  1397.       {
  1398.        td[jhword->Arg3].Request->io_Data=fBuffer;
  1399.        td[jhword->Arg3].Request->io_Length=tSize;
  1400.        td[jhword->Arg3].Request->io_Offset=jhword->Arg2*tSize;
  1401.        td[jhword->Arg3].Request->io_Command=TD_FORMAT;
  1402.        i=DoIO(td[jhword->Arg3].Request);
  1403.        if(i==0)
  1404.         {
  1405.          if(jhword->Arg4==1)
  1406.           {
  1407.            td[jhword->Arg3].Request->io_Command=CMD_READ;
  1408.            i=DoIO(td[jhword->Arg3].Request);
  1409.            if(i!=0) res=4;
  1410.           }
  1411.         } else res=3;
  1412.       }
  1413.      else
  1414.       {
  1415.        Seek(td[jhword->Arg3].FileHandle,jhword->Arg2*tSize,OFFSET_BEGINNING);
  1416.        i=Write(td[jhword->Arg3].FileHandle,fBuffer,tSize);
  1417.        if(i!=tSize) res=3;
  1418.       }
  1419.     } else res=2;
  1420.    MotorCNT[Active]=ud[Active].Motor;
  1421.    MotorCNT[jhword->Arg3]=ud[jhword->Arg3].Motor;
  1422.    FreeMem(fBuffer,tSize);
  1423.   } else res=1;
  1424.  jhword->Arg2=res;
  1425. }
  1426.  
  1427.  
  1428. /* Information */
  1429. VOID ShowInfo()
  1430. {
  1431.  InformationBox("ATUtilities Disk Transfer - Information",
  1432.                 "$VER: Disk Transfer - Version 4.0",
  1433.                 "Copyright (C) 1992-1994 by",
  1434.                 "Thomas Dreibholz",
  1435.                 "All rights reserved.",
  1436.                 "AT:Icons/Utility");
  1437. }
  1438.  
  1439.